package com.ericssonlabs;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.qrcodeandpay.R;
import com.google.zxing.WriterException;
import com.zxing.encoding.EncodingHandler;

public class CreateQRCode extends Activity{
	private ImageView createQRCodeImage;
	private EditText createQRCodeEdit;
	private Button ok;
	private Bitmap resBitmap=null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(com.example.qrcodeandpay.R.layout.create_qrcode);
		createQRCodeImage=(ImageView) findViewById(R.id.createQRCodeImg);
		createQRCodeEdit=(EditText) findViewById(R.id.e1);
		ok=(Button) findViewById(R.id.ok);
		ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String res=createQRCodeEdit.getText().toString();
				if(!TextUtils.isEmpty(res)){
					try {
						resBitmap=EncodingHandler.createQRCode(res, 500, 500);
						createQRCodeImage.setImageBitmap(resBitmap);
					} catch (WriterException e) {
						e.printStackTrace();
						Toast.makeText(CreateQRCode.this, "我草生成出错了,等我去看下!", Toast.LENGTH_LONG).show();
					}
				}else{
					Toast.makeText(CreateQRCode.this, "哥们你逗我玩呢？输入内容撒", Toast.LENGTH_LONG).show();
				}
			}
		});
	}
	@Override
	protected void onDestroy() {
		super.onDestroy();
		if(resBitmap!=null && !resBitmap.isRecycled()){
			resBitmap.recycle();
			resBitmap=null;
		}
	}
}
